From: Po Lu Date: Wed, 13 Jul 2022 03:01:59 +0000 (+0800) Subject: Fix closing displays when preserving selections is enabled X-Git-Tag: archive/raspbian/1%29.2+1-2+rpi1^2~5^2~16^2~1886^2~973 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=6be201cf51e0b1c69e713dec318cef18eef4c617;p=emacs.git Fix closing displays when preserving selections is enabled * src/frame.c (delete_frame): Bind `x-auto-preserve-selections' to nil if deleting display. * src/xselect.c (x_clear_frame_selections): Pass original frame to that function. * src/xterm.c (x_preserve_selections): Fix determining the new owner. (syms_of_xterm): New defsym `x-auto-preserve-selections'. * src/xterm.h: Update prototypes. --- diff --git a/src/frame.c b/src/frame.c index 923ef2d609a..a39e1c4944f 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1933,6 +1933,9 @@ delete_frame (Lisp_Object frame, Lisp_Object force) int is_tooltip_frame; bool nochild = !FRAME_PARENT_FRAME (f); Lisp_Object minibuffer_child_frame = Qnil; +#ifdef HAVE_X_WINDOWS + specpdl_ref ref; +#endif if (!FRAME_LIVE_P (f)) return Qnil; @@ -2116,7 +2119,18 @@ delete_frame (Lisp_Object frame, Lisp_Object force) /* Clear any X selections for this frame. */ #ifdef HAVE_X_WINDOWS if (FRAME_X_P (f)) - x_clear_frame_selections (f); + { + /* Don't preserve selections when a display is going away, since + that sends stuff down the wire. */ + + ref = SPECPDL_INDEX (); + + if (EQ (force, Qnoelisp)) + specbind (Qx_auto_preserve_selections, Qnil); + + x_clear_frame_selections (f); + unbind_to (ref, Qnil); + } #endif #ifdef HAVE_PGTK diff --git a/src/xselect.c b/src/xselect.c index baab2c5c18f..1750cfb8bd8 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -1128,7 +1128,7 @@ x_clear_frame_selections (struct frame *f) } if (x_auto_preserve_selections) - x_preserve_selections (dpyinfo, lost); + x_preserve_selections (dpyinfo, lost, frame); } /* True if any properties for DISPLAY and WINDOW diff --git a/src/xterm.c b/src/xterm.c index 6e3a941719d..fa54d5c9e28 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -27956,7 +27956,8 @@ x_uncatch_errors_for_lisp (struct x_display_info *dpyinfo) being deleted. */ void -x_preserve_selections (struct x_display_info *dpyinfo, Lisp_Object lost) +x_preserve_selections (struct x_display_info *dpyinfo, Lisp_Object lost, + Lisp_Object current_owner) { Lisp_Object tail, frame, new_owner, tem; Time timestamp; @@ -27975,6 +27976,7 @@ x_preserve_selections (struct x_display_info *dpyinfo, Lisp_Object lost) FOR_EACH_FRAME (tail, frame) { if (FRAME_X_P (XFRAME (frame)) + && !EQ (frame, current_owner) && FRAME_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) { new_owner = frame; @@ -28105,6 +28107,7 @@ syms_of_xterm (void) DEFSYM (Qlatin_1, "latin-1"); DEFSYM (Qnow, "now"); DEFSYM (Qx_dnd_targets_list, "x-dnd-targets-list"); + DEFSYM (Qx_auto_preserve_selections, "x-auto-preserve-selections"); #ifdef USE_GTK xg_default_icon_file = build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg"); diff --git a/src/xterm.h b/src/xterm.h index 9b91ee45569..6afd08eab2b 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1643,7 +1643,8 @@ extern void xic_set_statusarea (struct frame *); extern void xic_set_xfontset (struct frame *, const char *); extern bool x_defined_color (struct frame *, const char *, Emacs_Color *, bool, bool); -extern void x_preserve_selections (struct x_display_info *, Lisp_Object); +extern void x_preserve_selections (struct x_display_info *, Lisp_Object, + Lisp_Object); #ifdef HAVE_X_I18N extern void free_frame_xic (struct frame *); # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT